﻿
Imports System.IO
Imports xmlctrl
Imports xhtmlctrl
Imports webctrl

Public Class inputpage
    Inherits cacheProcessor
    'handle /input?url=abc&tag=abc, render a page to submit a new rss feed

    Public Const _pathidentity As String = "/input"
    Public Const urlquery As String = "url"
    Public Const tagquery As String = "tag"

    Protected Overrides Function processImpl(ByVal context As httpContext) As Boolean
        Dim buff As MemoryStream = Nothing
        buff = context.buff()

        Dim url As String = Nothing
        Dim tag As String = Nothing
        url = context.url.query(urlquery)
        tag = context.url.query(tagquery)

        Dim page As xhtmlpage = Nothing
        page = New xhtmlpage(buff)
        page.title().text() = applicationSign() + "please input rss link and related tags - "
        page.addcsslink(staticrequest.generateStaticfileLinkUrl("inputpage.css"))

        Dim form As form = Nothing
        form = New form(buff)
        form.action = strmid(submitpage._pathidentity, strlen(network.pathSeperator))
        page.body().addchild(form)

        Dim label As label = Nothing
        label = New label(buff)
        label.text = "please input rss link here."
        form.addchild(label)

        Dim br As br = Nothing
        br = New br(buff)
        form.addchild(br)

        Dim input As input = Nothing
        input = New input(buff)
        input.type = xhtmlctrl.input.type_enum.text
        input.name = submitpage.urlquery
        input.value = ifoper(isemptystring(url), network.httpAddressHeader, url)
        form.addchild(input)

        br = New br(buff)
        form.addchild(br)

        label = New label(buff)
        label.text = "please input related tags here, use blank to seperate."
        form.addchild(label)

        br = New br(buff)
        form.addchild(br)

        input = New input(buff)
        input.type = xhtmlctrl.input.type_enum.text
        input.name = submitpage.tagquery
        input.value = tag
        form.addchild(input)

        br = New br(buff)
        form.addchild(br)

        input = New input(buff)
        input.type = xhtmlctrl.input.type_enum.submit
        input.id = "id_s"
        input.value = "submit"
        form.addchild(input)

        assert(page.render(Not isdebugmode()), "failed to render inputpage.")
        Return True
    End Function

    Public Overrides Function pathidentity() As String
        Return _pathidentity
    End Function

    Public Overrides Function pathidentitylen() As Long
        Return strlen(pathidentity())
    End Function
End Class
